﻿#include "HelpCommand.h"

#include "../../Memory/GameData.h"
#include "../CommandsManager.h"

bool HelpCommand_onExecute(const fast_io::vector<std::u8string>& args) {
	if (args.size() > 1)
		return false;

	constexpr auto CommandsCount = CommandMgr::getCommandsCount();

	fast_io::vector<std::pair<std::u8string_view*, std::u8string_view*>> completeList{};
	completeList.reserve(CommandsCount);

	for (size_t i = 0; i < CommandsCount; i++)
		completeList.emplace_back_unchecked(&CommandMgr::commandList[i]->_command, &CommandMgr::commandList[i]->_description.at(SettingManager::languageget));

	std::ranges::sort(completeList, [](std::pair<std::u8string_view*, std::u8string_view*>& a, std::pair<std::u8string_view*, std::u8string_view*>& b) { return *a.first < *b.first; });  // sort

	C_GuiData::displayClientMessageC(Utils::TextColor::GRAY, u8"========================");
	for (auto& i : completeList)
		C_GuiData::displayClientMessageC(fast_io::mnp::chvw(CommandMgr::prefix), Utils::TextColor::GRAY, *i.first, Utils::TextColor::WHITE, u8" - ", Utils::TextColor::YELLOW, *i.second);

	return true;
}

ICommand HelpCommand{
	u8"help",
	u8".help or .?",
	{u8"List all commands", u8"列出所有的命令", u8"列出所有的命令", u8"すべてのコマンドを一覧表示する"},
	{u8"?"},
	fast_io::vector<aliasList_struct>{},  // If empty must use fast_io::vector<aliasList_struct>{}
	nullptr,
	&HelpCommand_onExecute};
